package com.ph.demo.io;

import java.io.*;

/**
 * 文件字节输出流
 */
public class ByteArrayDemo2 {

    public static void main(String[] args)  {

        File file =new File("dest.txt");

        OutputStream outputStream = null;

        try {
            outputStream = new FileOutputStream(file,true);

            //3。操作  写出

            String io = "io is so easy";

            byte[] bytes = io.getBytes();

            outputStream.write(bytes);

            outputStream.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //释放资源  先打开的后关闭
            try {
                if (outputStream!= null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
